package com.itfitness.cppdemoone.activity

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.util.Log
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.itfitness.cppdemoone.R
import com.itfitness.cppdemoone.databinding.ActivityBoundaryfillBinding
import com.itfitness.cppdemoone.databinding.ActivityCutoutBinding

/**
 *
 * @Description:     java类作用描述 抠图
 * @Author:         作者名
 * @CreateDate:     2022/2/23 17:01
 * @UpdateUser:     更新者：
 * @UpdateDate:     2022/2/23 17:01
 * @UpdateRemark:   更新说明：
 */
class CutoutActivity:AppCompatActivity(){
    private lateinit var cutoutBinding: ActivityCutoutBinding
    private var minH = 0
    private var minS = 0
    private var minV = 0
    private var maxH = 0
    private var maxS = 0
    private var maxV = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        cutoutBinding = DataBindingUtil.setContentView(this, R.layout.activity_cutout)
        val bitmapSrc = BitmapFactory.decodeResource(resources,R.drawable.img_1)
        cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
        cutoutBinding.activityCutoutSMinH.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                minH = progress
                Log.e("minH","$minH")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
        cutoutBinding.activityCutoutSMinS.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                minS = progress
                Log.e("minS","$minS")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
        cutoutBinding.activityCutoutSMinV.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                minV = progress
                Log.e("minV","$minV")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
        cutoutBinding.activityCutoutSMaxH.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                maxH = progress
                Log.e("maxH","$maxH")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
        cutoutBinding.activityCutoutSMaxS.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                maxS = progress
                Log.e("maxS","$maxS")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
        cutoutBinding.activityCutoutSMaxV.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                maxV = progress
                Log.e("maxV","$maxV")
                cutoutBinding.activityCutoutImgDest.setImageBitmap(imageCutout(bitmapSrc,minH,minS,minV,maxH,maxS,maxV))
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {

            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {

            }
        })
    }



    external fun imageCutout(bitmapSrc:Bitmap,minH:Int,minS:Int,minV:Int,maxH:Int,maxS:Int,maxV:Int):Bitmap
}